﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BrokerBase.Lib.Policy;

namespace broker.duty.YG
{
    class Class22
    {
        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            double pfee = 0f;
            double bfee = 0f;
            double afee = 0f;
            double deduct = 0f;
            double efee = 0f;

            int overPeriod = Convert.ToInt32(ppa.SchemePeriodActing.SchemeActing.GetAuxConfigValue("约定缴费期(年)"));

            double cof = Convert.ToDouble(ppa.SchemePeriodActing.SchemeActing.GetAuxConfigValue("稳健型账户比例"));


            if (ppa.Period < overPeriod)
            {

                pfee = Convert.ToDouble(ppa.SchemePeriodActing.SchemeActing.GetAuxConfigValue("期交保险费"));
                bfee = 6000f;
                afee = pfee - bfee;
                deduct = 0f;

                if (afee < 0)
                {
                    throw new Exception("期交保险费不能低于6000元!");
                }

                switch (ppa.Period)
                {
                    case 0:
                        deduct = bfee * 0.5;
                        break;
                    case 1:
                        deduct = bfee * 0.25;
                        break;
                    case 2:
                        deduct = bfee * 0.15;
                        break;
                    case 3:
                    case 4:
                        deduct = bfee * 0.1;
                        break;
                    default:
                        deduct = bfee * 0.05;
                        break;
                }

                deduct += afee * 0.05;

            }





            deduct += 60;//保单管理费;

            if (ppa.Period < ppa.PolicyActing.Policy.Fees.Count())
            {
                double d = ppa.PolicyActing.Policy.Fees[ppa.Period];
                if (d <= double.Epsilon)
                {
                    d = (double)ppa.PolicyActing.PeriodActings[ppa.Period - 1].Tag;
                }
                ppa.Tag = d;
                deduct += d;//约定风险金对应的保费

            }

            if (ppa.SchemePeriodActing.InsurantStates.Contains("追加费用"))
            {
                efee = Convert.ToInt32(ppa.SchemePeriodActing.SchemeActing.GetAuxConfigValue("追加费用"));
            }

            deduct += efee * 0.05;//追加的费用的初始费用
            da.Value = (pfee + efee - deduct) * cof;

            if (ppa.Period > 0)
            {
                double f = (double)ppa.SchemePeriodActing.SchemeActing.GetAuxConfigValue("稳健型年利率");
                IPolicyPeriodActing pppa = ppa.PolicyActing.PeriodActings[ppa.Period - 1];
                da.Value += pppa.GetDutyTotalValue("稳健型账户") * f;
            }

            if (ppa.Period > 3 && ppa.Period < overPeriod)
            {
                da.Value += pfee * 0.02;
            }

            ppa.Fee = pfee + efee;

            if (ppa.GetDutyTotalValue("稳健型账户")+ppa.GetDutyTotalValue("进取型账户") <= 0)
            {
                ppa.IsCurrentFinish = true;
                da.Description = "个人账户余额不足，合同终止!";
            }

        }


        public void Calc1(IPolicyPeriodActing ppa, IDutyActing da)
        {
            double pfee = 0f;
            double bfee = 0f;
            double afee = 0f;
            double deduct = 0f;
            double efee = 0f;

            int overPeriod = Convert.ToInt32(ppa.SchemePeriodActing.SchemeActing.GetAuxConfigValue("约定缴费期(年)"));

            double cof =1- Convert.ToDouble(ppa.SchemePeriodActing.SchemeActing.GetAuxConfigValue("稳健型账户比例"));


            

            if (ppa.Period < overPeriod)
            {

                pfee = Convert.ToDouble(ppa.SchemePeriodActing.SchemeActing.GetAuxConfigValue("期交保险费"));
                bfee = 6000f;
                afee = pfee - bfee;
                deduct = 0f;

                if (afee < 0)
                {
                    throw new Exception("期交保险费不能低于6000元!");
                }

                switch (ppa.Period)
                {
                    case 0:
                        deduct = bfee * 0.5;
                        break;
                    case 1:
                        deduct = bfee * 0.25;
                        break;
                    case 2:
                        deduct = bfee * 0.15;
                        break;
                    case 3:
                    case 4:
                        deduct = bfee * 0.1;
                        break;
                    default:
                        deduct = bfee * 0.05;
                        break;
                }

                deduct += afee * 0.05;

            }





            deduct += 60;//保单管理费;

            if (ppa.Period < ppa.PolicyActing.Policy.Fees.Count())
            {
                double d = ppa.PolicyActing.Policy.Fees[ppa.Period];
                if (d <= double.Epsilon)
                {
                    d = (double)ppa.PolicyActing.PeriodActings[ppa.Period - 1].Tag;
                }
                ppa.Tag = d;
                deduct += d;//约定风险金对应的保费

            }

            if (ppa.SchemePeriodActing.InsurantStates.Contains("追加费用"))
            {
                efee = Convert.ToInt32(ppa.SchemePeriodActing.SchemeActing.GetAuxConfigValue("追加费用"));
            }

            deduct += efee * 0.05;//追加的费用的初始费用
            da.Value = (pfee + efee - deduct) * cof;

            if (ppa.Period > 0)
            {
                double f = (double)ppa.SchemePeriodActing.SchemeActing.GetAuxConfigValue("进取型年利率");
                IPolicyPeriodActing pppa = ppa.PolicyActing.PeriodActings[ppa.Period - 1];
                da.Value += pppa.GetDutyTotalValue("进取型账户") * f;
            }

            if (ppa.Period > 3 && ppa.Period < overPeriod)
            {
                da.Value += pfee * 0.02;
            }

            ppa.Fee = pfee + efee;

            if (ppa.GetDutyTotalValue("稳健型账户") + ppa.GetDutyTotalValue("进取型账户") <= 0)
            {
                ppa.IsCurrentFinish = true;
                da.Description = "个人账户余额不足，合同终止!";
            }

        }
    }
}
